import * as uniIdPagesStore from '@/uni_modules/uni-id-pages/common/store'
export default {
    namespaced: true,
    state: {
		myUserInfo:{},
		userWallet:{
			freeze_amount:`0.00`,
			available_amount:`0.00`
		},
		merchantOrderDashboard:{
			progress:0,
			success:0,
			error:0,
			total:0
		}
	},
    mutations: {
		changeMyUserInfo(state,data){
			state.myUserInfo=data;
		},
		changeUserWallet(state,data){
			state.userWallet=data;
		},
		changeOrderDashboard(state,data){
			state.merchantOrderDashboard=data;
		}
	},
    actions: {
		getUserInfo ({commit}) {
			const db = uniCloud.database()
			return db
				.collection('uni-id-users')
				.where('_id==$cloudEnv_uid')
				.field('username,nickname,mobile,email,role,permission,avatar_file,merchant_id')
				.get()
				.then(({result}) => {
					const [userInfo] = result.data

					uniIdPagesStore.mutations.setUserInfo(userInfo, true)
					commit(`changeMyUserInfo`,userInfo)
					return Promise.resolve(userInfo)
				})
		}
	}
}
